package com.pany.rememberpass.Adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pany.rememberpass.R;
import com.pany.rememberpass.bean.ItemBean;

import java.util.List;

/**
 * @name： RememberPass
 * @author： zs
 * @time： 2022/5/9 0009
 */
public class MyBaseAdapter extends BaseAdapter {
    private List<ItemBean> itemBeanList;
    private Context context;
    private LayoutInflater myLayoutInflater;

    public MyBaseAdapter(List<ItemBean> itemBeanList, Context context) {
        this.itemBeanList = itemBeanList;
        this.context = context;
        myLayoutInflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return itemBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return itemBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("ViewHolder")
    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        convertView = myLayoutInflater.inflate(R.layout.list_item_layout, viewGroup, false);
        ImageView iv_icon = convertView.findViewById(R.id.iv_icon);
        TextView tv_content = convertView.findViewById(R.id.tv_content);
        TextView tv_title = convertView.findViewById(R.id.tv_title);

        ItemBean itemBean = itemBeanList.get(i);
        String content = itemBean.getContent();
        String title = itemBean.getTitle();
        int imgRId = itemBean.getImgRId();

        iv_icon.setImageResource(imgRId);
        tv_content.setText(content);
        tv_title.setText(title);

        return convertView;
    }
}
